﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.FactoryManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.FactoryManagement.LineShiftVMs
{
    public partial class LineShiftListVM : BasePagedListVM<LineShift_View, LineShiftSearcher>
    {
        
        protected override IEnumerable<IGridColumn<LineShift_View>> InitGridHeader()
        {
            return new List<GridColumn<LineShift_View>>{
                
                this.MakeGridHeader(x => x.LineShift_Line).SetTitle(@Localizer["Page.产线"].Value),
                this.MakeGridHeader(x => x.LineShift_LineName).SetTitle(@Localizer["Page.产线名称"].Value),
                this.MakeGridHeader(x => x.LineShift_Name).SetTitle(@Localizer["Page.班次"].Value),
                this.MakeGridHeader(x => x.LineShift_Code).SetTitle(@Localizer["Page.班次编码"].Value),
                this.MakeGridHeader(x => x.LineShift_StartTime).SetTitle(@Localizer["Page.开始时间"].Value).SetFormat((x,y)=>
                {

                    if (x.LineShift_StartTime.HasValue)
                    {
                         return x.LineShift_StartTime.Value.ToString("HH:mm:ss");
                    }
                    return null;
                  }
                 
                ),
                this.MakeGridHeader(x => x.LineShift_EndTime).SetTitle(@Localizer["Page.结束时间"].Value).SetFormat((x,y)=>x.LineShift_EndTime?.ToString("HH:mm:ss")),
                this.MakeGridHeader(x => x.LineShift_Hours).SetTitle(@Localizer["_Admin.Duration"].Value),
                this.MakeGridHeader(x => x.LineShift_CrossDays).SetTitle(@Localizer["Page.跨天"].Value),
                this.MakeGridHeader(x => x.LineShift_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.LineShift_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.LineShift_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.LineShift_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<LineShift_View> GetSearchQuery()
        {
            var query = DC.Set<LineShift>()
                
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineName, x=>x.LineName)
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckBetween(Searcher.StartTime?.GetStartTime(), Searcher.StartTime?.GetEndTime(), x => x.StartTime, includeMax: false)
                .CheckBetween(Searcher.EndTime?.GetStartTime(), Searcher.EndTime?.GetEndTime(), x => x.EndTime, includeMax: false)
                .CheckEqual(Searcher.Hours, x=>x.Hours)
                .CheckEqual(Searcher.CrossDays, x=>x.CrossDays)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new LineShift_View
                {
				    ID = x.ID,
                    
                    LineShift_Line = x.Line.Name,
                    LineShift_LineName = x.Line.Name,
                    LineShift_Name = x.Name,
                    LineShift_Code = x.Code,
                    LineShift_StartTime = x.StartTime,
                    LineShift_EndTime = x.EndTime,
                    LineShift_Hours = x.Hours,
                    LineShift_CrossDays = x.CrossDays,
                    LineShift_CreateTime = x.CreateTime,
                    LineShift_UpdateTime = x.UpdateTime,
                    LineShift_CreateBy = x.CreateBy,
                    LineShift_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class LineShift_View: LineShift
    {
        
        public string LineShift_Line { get; set; }
        public string LineShift_LineName { get; set; }
        public string LineShift_Name { get; set; }
        public string LineShift_Code { get; set; }
        public DateTime? LineShift_StartTime { get; set; }
        public DateTime? LineShift_EndTime { get; set; }
        public decimal? LineShift_Hours { get; set; }
        public bool? LineShift_CrossDays { get; set; }
        public DateTime? LineShift_CreateTime { get; set; }
        public DateTime? LineShift_UpdateTime { get; set; }
        public string LineShift_CreateBy { get; set; }
        public string LineShift_UpdateBy { get; set; }

    }

}